﻿using System.IO;
using System;

namespace hcrainface.Dto
{
    public class FaceimgInfo
    {
        public bool MoreAddUserInfo = false;
        /// <summary>
        /// // 比对阈值，默认0.8
        /// </summary>
        public string minScore = "0.8";
        public string topK = "1";

        /// <summary>
        /// 馆代码
        /// </summary>
        public string OrgCode { get; set; } = null;
        //public IFormFile File { get; set; } = null;
        public string ImgBase64 { get; set; } = null;
        public string UserName { get; set; } = null;
        /// <summary>
        /// 我方的用户ID
        /// </summary>
        public string SysUserId { get; set; } = null;
        /// <summary>
        /// 对方的用户ID
        /// </summary>
        public string FaceUserId { get; set; } = null;

        public string ImgPath { get; set; }

        public string getImgPath()
        {
            if (ImgPath != null && ImgPath.Length > 50) return ImgPath;
            var imgBase64 = ImgBase64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "")
      .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");
            var photoBytes = Convert.FromBase64String(imgBase64);
            var filePath = SysUserId + ".jpg";
            File.WriteAllBytes(filePath, photoBytes);
            return filePath;


        }
        public MemoryStream GetMemoryStream()
        {
            if (ImgBase64 != null)
            {
                ImgBase64 = ImgBase64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "")
    .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");
                byte[] arr = Convert.FromBase64String(ImgBase64);
                return new MemoryStream(arr);
            }
            else
            {
                throw new Exception("图片ImgBase64不能为空");
                //var memoryStream = new MemoryStream();
                //File.CopyTo(memoryStream);
                //return memoryStream;
            }
        }
    }

}
